<%@page import="org.upt.dcda.presentation.BookInformation"%>
<%@page import="org.upt.dcda.presentation.SessionAttributes"%>
<%@page import="org.upt.dcda.db.UserEntity"%>
<%@page import="org.upt.dcda.db.TagEntity"%>
<%@page import="org.upt.dcda.presentation.TagInformationExtended"%>
<%@page import="java.util.List"%>
<%@ taglib prefix="stripes"
	uri="http://stripes.sourceforge.net/stripes.tld"%>
<%
if(!SessionAttributes.isAdmin(request)) {
	response.sendRedirect("login.jsp");
} else {
%>
<stripes:layout-render name="layout/default.jsp"
	pageTitle="Using A Layout">

	<stripes:layout-component name="pageTitle">
	Modify Book
 	</stripes:layout-component>

	<stripes:layout-component name="html_head">
		<script type="text/javascript">
			function getBookInfo(id) {
				$
						.ajax({
							url : 'services/books/getInfo?id=' + id,
							async : false,
							dataType : 'json',
							success : function(data) {
								$('#bookInfo > tbody:last')
										.append(
												'<tr>'
														+ '<td>'
														+ '<input type="text" name="title" value="' + data.name + '">'
														+ '</td>'
														+ '<td>'
														+ '<select id="authors" name="authors"></select>'
														+ '</td>'
														+ '<td>'
														+ '<input type="text" name="price" value="' + data.price + '">'
														+ '</td>'
														+ '<td>'
														+ '<input type="text" name="description" value="' + data.description + '">'
														+ '</td>');

							}
						});

				reloadAuthors('#authors');
			}

			$(document).ready(function() {
				getBookInfo(
		<%=request.getParameter("id")%>
			);
			});
		</script>
	</stripes:layout-component>

	<stripes:layout-component name="contents">

		<form action="modifybook" method="post">

			<table id="bookInfo">
				<tbody>
					<tr>
						<th>Title</th>
						<th>Author</th>
						<th>Price</th>
						<th>Description</th>
					</tr>
				</tbody>
			</table>
			
			<input type="hidden" name="bookId"
				value="<%=request.getParameter("id")%>" /> <input type="submit"
				value="Update" />
		</form>

	</stripes:layout-component>

</stripes:layout-render>
<%
}
%>